package io.iec.edp.caf.core.session;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangyandong
 */
@Slf4j
public class BackendSessionHolder implements CafSessionHolder {
    /**
     * 返回匹配的Session类型
     *
     * @return
     */
    @Override
    public List<SessionType> getMatchingSessionTypes() {
        List<SessionType> list = new ArrayList<>();
        list.add(SessionType.backend);
        return list;
    }

    /**
     * 获取当前的Session对象
     */
    @Override
    public CafSession getCurrentSession() {
        return CafSessionThreadHolder.getCurrentSession();
    }

    @Override
    public CafSession getCopyedCurrentSession() {
        return getCurrentSession();
    }

    /**
     * 获取当前的Session对象
     *
     * @param session
     */
    @Override
    public void setCurrentSession(CafSession session) {
        CafSessionThreadHolder.setCurrentSession(session);
    }

    @Override
    public void setCurrentThreadPoolSession(CafSession session) {
        setCurrentSession(session);
    }

    /**
     * 清理当前Session
     */
    @Override
    public void clear() {
        log.info("清理backend session操作："+Thread.currentThread().getName(),new Exception());
        CafSessionThreadHolder.purge();
    }

    @Override
    public void clearCurrentThreadPoolSession() {
        clear();
    }
}
